import React from 'react'
import ReactDom from 'react-dom/client'
import './index.css'
import App from './App.jsx'
import { renderWithQiankun, qiankunWindow } from "vite-plugin-qiankun/dist/helper";

const initQianKun = () => {
  renderWithQiankun({
    // 把要用的写在前面
    mount(props) {
      render(props);
    },
    bootstrap() {},
    unmount() {},
  });
};

const render = (props = {}) => {
  // 如果是在主应用的环境下就挂载主应用的节点，否则挂载到本地
  const { container, setGlobalState, getGlobalState } = props;
  const appDom = container ? container : document.getElementById("root");
  ReactDom.createRoot(appDom).render(
    <React.StrictMode>
      <App setGlobalState={setGlobalState} getGlobalState={getGlobalState} />
    </React.StrictMode>
  );
};

// 判断当前应用是否在主应用中
qiankunWindow.__POWERED_BY_QIANKUN__ ? initQianKun() : render();

// createRoot(document.getElementById('root')).render(
//   <StrictMode>
//     <App />
//   </StrictMode>,
// )
